//var colorList;
var stepTextList;
var count;

//页面跳转
//function methodBtn(index, method, end) {
//    var fFor;
//    if (end != true) {
//        if (method == "back") {//back暂时没用
//            if (index == 1) {
//                fFor = ".for" + String.fromCharCode(index + 65);
//            } else {
//                fFor = ".for" + String.fromCharCode(index + 64);
//            }
//            $(fFor).removeClass("for-cur");
//            //loadFlowDiv(index-1);
//            checkColor("default");
//        } else if (method == "forward") {
//            fFor = ".for" + String.fromCharCode(index + 65);
//            $(fFor).addClass("for-cur");
//            $(fFor).find("span").empty();
//            /*保存失败回滚到之前某步骤时，某步骤之后的步骤重置为没走流程状态 start*/
//            var nextflowList = $(fFor).nextAll();
//            nextflowList.removeClass("for-cur");
//            nextflowList.css({ "border": "2px solid #ccc", "background-color": "#ccc" }); //某步骤之后的步骤置灰
//            nextflowList.children("em").css({ "background-color": "#ccc" });//某步骤之后的步骤置灰
//            nextflowList.find("span").empty();
//            /*end */
//            //loadFlowDiv(index+1);
//            checkColor(colorList);
//        }
//    } else if (end == true) {

//    }

//}

//确定流程颜色状态
//function checkColor(color) {

//    if (color != "default") {//走完的步骤设置成绿色
//        $(".flowList.for-cur").css({ "border": "2px solid #1ABB9C" });
//        $(".flowList.for-cur,.flowListBox .for-cur em").css({ "background-color": "#1ABB9C" });
//        $(".flowListBox .for-cur em").css({ "border": "0px none #000" });
//    } else {
//        $this = $('.flowList:not(.for-cur)');
//        $this.css({ "border": "2px solid #ccc", "background-color": "#ccc" });
//        $this.children("em").css({ "background-color": "#ccc" });
//    }
//    /*让当前选中步骤变为深蓝色*/
//    var obj = $('.for-cur:last');
//    obj.css({ "border": "2px solid #34495e", "background-color": "#34495e" });
//    obj.children("em").css({ "background-color": "#34495e" });
//}
//确定步骤的宽度占比
//function fixWidth(count) {
//    var part = parseInt(100 / count) - 1 + "%";
//    $(".flowListBox .flowList").css("width", part);
//}

//加载步骤默认是灰色
//function loadFlow(count){
//  var flowFor;
//  var flowVar="";
//  for(var i=1;i<=count;i++){
//    flowFor="for"+String.fromCharCode(i+64);
//    if(i==1){
//      flowVar += "<div class='flowList for-cur "+flowFor +"' style='position:relative'>\n";
//      flowVar += "	<em style='position:absolute;left:40%'>" + i + "</em><br/><strong style='position:absolute;left:35%' >" + getStepText(i) + "</br><span  id='step_" + i + "'></span></strong>\n";
//      flowVar += "</div>\n";
//    }else{
//      flowVar += "<div class='flowList "+flowFor +"' style='position:relative'>\n";
//      flowVar += "	<em style='position:absolute;left:40%'>" + i + "</em><br/><strong style='position:absolute;left:35%' >" + getStepText(i) + "</br><span  id='step_" + i + "'></span></strong>\n";
//      flowVar += "</div>\n";
//    }

//  }
//  $(".flowListBox").html(flowVar);
//  fixWidth(count);
//}



/*初始化流程图*/
function initFlow(steps) {
    count = steps.length;
    stepTextList = steps;
    loadFlow(count);
}

function loadFlow(count) {
    var flowVar = "";
    for (var i = 1; i <= count; i++) {
        if (i == 1) {
            flowVar += " <li class='active'>" + i + "<p id='step_" + i + "'>" + getStepText(i) + "</p></li>";
        } else {
            flowVar += " <li>" + i + "<p id='step_" + i + "'>" + getStepText(i) + "</p></li>";
        }

    }
    $("ul", $(".ranger")).html(flowVar);
    fixWidth(count, 1);
}

function getStepText(index) {
    var text = '';
    if (stepTextList) {
        $(stepTextList).each(function (i, n) {
            if (index == i + 1) {
                text = n;
                return false;
            }
        });
    } else {
        text = '第' + index + '步';
    }
    return text;
}

function fixWidth(count, step) {
    var part = Math.round(parseFloat(100 / (count - 1)) * 1000) / 1000 * step;
    $(".slide").css("width", part + "%");
}

function methodBtn(step) {
    var rangerDiv = $(".ranger");
    var currStep = $("li:eq(" + step + ")", rangerDiv);
    var currNextStep = $("li:gt(" + step + ")", rangerDiv);
    $("li", rangerDiv).removeClass();
    $("li:lt(" + step + ")", rangerDiv).addClass("done");
    currStep.addClass("active");
    $("span", currStep).remove();
    $("span", currNextStep).remove();
    fixWidth(count, step);
}

function showMsg(msg, isPlaySound) {
    //$('#result').text(msg);
    $("span", $(".cont")).html(msg + "<ul><li></li><li></li><li></li></ul>");
    isPlaySound = isPlaySound == undefined ? true : isPlaySound;// 默认为启用
    if (isPlaySound) {
        soundService.play(iotBaseUrl+'/api/speech/Tts?msg=' + msg);
    }
}
